﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPFDemoMVVM.ViewModel
{
    public partial class ItemControlSortViewModel:ObservableObject
    {

        [ObservableProperty]
        public ObservableCollection<string> items = new ObservableCollection<string>() 
        { "aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk","ll","mm","nn","oo","pp","qq","rr","ss","tt","uu"};


        public ItemControlSortViewModel() { 
            UpdateIndexes();
        }


        [RelayCommand]
        public void Remove()
        {
            Items.RemoveAt(5);
            //OnPropertyChanged(nameof(Items));

            //OnPropertyChanged(nameof(Indexes));

            UpdateIndexes();
        }

        public IEnumerable<int> Indexes => Enumerable.Range(1, Items.Count);


        private void UpdateIndexes()
        {
            for (int i = 0; i < Items.Count; i++)
            {
                //Items[i].Index = i + 1;
            }
        }

    }

    public partial class Model : ObservableObject
    {
        [ObservableProperty]
        int? index;

        [ObservableProperty]
        string content;


        public static implicit operator Model(string c) => new Model { Content = c };

        public override string ToString()
        {
            return Content;
        }
    }

}
